package com.zzyl.controller.web;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 护理项目表 前端控制器
 * </p>
 *
 * @author 聂德祥
 * @since 2024-08-15
 */
@RestController
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;
    // 分页查询
    @GetMapping("/nursing_project")
    public ResponseResult getNursingProjectAll(
            String name,
            Integer status,
            @RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer page,
            @RequestParam(defaultValue = "5") Integer pageSize
    ){
        PageResponse<NursingProject> nursingProjectAll  = nursingProjectService.getNursingProjectAll(name,status,page,pageSize);
        return success(nursingProjectAll);
    }
    @PostMapping("/nursing_project")
    public ResponseResult addNusingProject(@RequestBody NursingProject nursingProject){
        // TODO 新增时需要加上创建人
        nursingProjectService.save(nursingProject);
        return success();
    }
    @GetMapping("/nursing_project/{id}")
    public  ResponseResult findNusingProjectById(@PathVariable Long id){
        NursingProject byId = nursingProjectService.getById(id);
        return success(byId);
    }
    @PutMapping("/nursing_project/{id}")
    public ResponseResult updateNusingProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateById(nursingProject);
        return success();
    }
    @PutMapping("/nursing_project/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectService.updateById(nursingProject);
        return success();
    }
    @DeleteMapping("/nursing_project/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id){
        // TODO 查看有无护理计划，有则不能删除

        nursingProjectService.removeByIdProject(id);
        return success();
    }
    @GetMapping("/nursing_project/all")
    public ResponseResult findAll(){
        List<NursingProject> list = nursingProjectService.list();
        return success(list);
    }
}
